#include "Frame.h"

Frame::Frame(const std::wstring title, const std::wstring id): Window(title, WS_OVERLAPPEDWINDOW, WS_EX_CLIENTEDGE) {
	setClassName(id);
}

Frame::~Frame() {
}

void Frame::setDefaultCloseOperation(const byte op) {
	closeOp = op;
}

void Frame::add(Component& com) {
	components.push_back(&com);
}

LRESULT Frame::processMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
	switch(msg) {
	case WM_CREATE:
		for(Component* c : components) {
			c->reparent(hwnd);
			c->create();
		}
		break;
	case WM_DESTROY:
		switch(closeOp) {
		case EXIT_ON_CLOSE:
			PostQuitMessage(0);
			break;
		case DISPOSE_ON_CLOSE:
			break;
		case HIDE_ON_CLOSE:
			setVisible(false);
		}
		break;
	default:
		return Window::processMessage(hwnd, msg, wParam, lParam);
	}
	return 0;
}

int Frame::frameId = 0;